package com.netease.xone.itemview;

import protocol.meta.User;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.google.gson.Gson;
import com.netease.image.ImageType;

import db.manager.ManagerDiscussTip;


public class ItemViewTipUser extends ItemViewTipBase {
    private int mPosition;
    private String mNickName;
    
    public ItemViewTipUser(Context context, int type) {
        super(context, type);
    }

    public ItemViewTipUser(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemViewTipUser(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void bindView(Cursor cursor) {
        mPosition = cursor.getPosition();
        String value = cursor.getString(ManagerDiscussTip.JSON);
        Gson gson = new Gson();
        User user = gson.fromJson(value, User.class);
        mNickName = user.nickname;
        mIcon.setLoadingImage(user.avatar, ImageType.RoundMemCache);
        mTitle.setText(user.nickname);
        mContent.setText(user.signature);
        
        if (TextUtils.isEmpty(mHashMap.get(mPosition))) {
            mCheckBox.setChecked(false);
        } else {
            mCheckBox.setChecked(true);
        }
        mCheckBox.setOnCheckedChangeListener(mOnCheckedChangeListener);
    }

    private OnCheckedChangeListener mOnCheckedChangeListener = new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
            	mHashMap.put(mPosition, mNickName);
            } else {
            	mHashMap.put(mPosition, null);
            }
        }
        
    };
}
